#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    int dx[4] = { -1, 1, 0, 0 };
    int dy[4] = { 0, 0, -1, 1 };
    int ret = 0;
    int count = 0;
    bool vis[50][50] = { false };
    int maxAreaOfIsland(vector<vector<int>>& grid) {
        for (int i = 0; i < grid.size(); i++)
        {
            for (int j = 0; j < grid[0].size(); j++)
            {
                count = 0;
                if (grid[i][j] == 1 && vis[i][j] == false)
                {
                    count++;
                    vis[i][j] = true;
                    dfs(grid, i, j);
                }
                ret = max(ret, count);
            }
        }
        return ret;
    }
    void dfs(vector<vector<int>>& grid, int x, int y)
    {
            for (int i = 0; i < 4; i++)
            {
                int x1 = x + dx[i];
                int y1 = y + dy[i];
                if (x1 >= 0 && x1 < grid.size() && y1 >= 0 && y1 < grid[0].size()
                    && grid[x1][y1] == 1 && vis[x1][y1] == false)
                {
                    vis[x1][y1] = true;
                    count++;
                    dfs(grid, x1, y1);
                }
            }
    }
};

int main()
{
    Solution s;
    vector<vector<int>> grid = { {0,0,1,0,0,0,0,1,0,0,0,0,0},
        {0,0,0,0,0,0,0,1,1,1,0,0,0},
        {0,1,1,0,1,0,0,0,0,0,0,0,0},
        {0,1,0,0,1,1,0,0,1,0,1,0,0},
        {0,1,0,0,1,1,0,0,1,1,1,0,0},
        {0,0,0,0,0,0,0,0,0,0,1,0,0},
        {0,0,0,0,0,0,0,1,1,1,0,0,0},
        {0,0,0,0,0,0,0,1,1,0,0,0,0} };
    int r = s.maxAreaOfIsland(grid);
    cout << r;
    return 0;
}